import { assign } from 'lodash';

const env = process.env.NODE_ENV || 'development';

// 默认配置
const dailyOffDutyMessage =
  '【客服已下班，本条消息为自动回复】\n\n亲爱的家长，您的信息已经收到，客服上班后会第一时间回复您哦~\n（客服值班时间：每天9:00~21:00）';

const chineseYearReply1 =
  '您好，除夕及初一期间客服值班时间为9:30-15:30 \n课程相关事宜，请先留言，客服上班后将尽快回复您。感谢您的理解与支持。Qkids久趣祝您新春快乐！';

const chineseYearReply2 =
  '您好，春节期间客服值班时间为9:00-21:00 \n课程相关事宜，请先留言，客服上班后将尽快回复您。感谢您的理解与支持。Qkids久趣祝您新春快乐！';

const defaultConf = {
  /**
   * 客服非值班时间,可使用%today%来指代当天
   * 如 %today 00:00:00% 在2012年10月11日将被格式化为 '2012/10/11 00:00:00',
   * 对于节假日，可在日常之前书写，将按照offDutyRange的顺序进行匹配，
   * 并返回第一个匹配结果
   */
  offDutyRange: [
    // 节假日
    {
      start: '2018/02/14 21:00',
      end: '2018/02/15 09:30',
      message: chineseYearReply1,
    },
    {
      start: '2018/02/15 15:30',
      end: '2018/02/16 09:30',
      message: chineseYearReply1,
    },
    {
      start: '2018/02/16 15:30',
      end: '2018/02/17 08:00',
      message: chineseYearReply1,
    },
    {
      start: '2018/02/17 21:20',
      end: '2018/02/18 08:00',
      message: chineseYearReply2,
    },
    {
      start: '2018/02/18 21:20',
      end: '2018/02/19 08:00',
      message: chineseYearReply2,
    },
    {
      start: '2018/02/19 21:20',
      end: '2018/02/20 08:00',
      message: chineseYearReply2,
    },
    {
      start: '2018/02/20 21:20',
      end: '2018/02/21 08:00',
      message: chineseYearReply2,
    },
    {
      start: '2018/02/21 21:20',
      end: '2018/02/22 08:00',
      message: chineseYearReply2,
    },
    {
      start: '2018/02/22 21:20',
      end: '2018/02/23 08:00',
      message: chineseYearReply2,
    },
    // 日常匹配
    {
      start: '%today% 00:00:00',
      end: '%today% 08:00:00',
      message: dailyOffDutyMessage,
    },
    {
      start: '%today% 21:30:00',
      end: '%today% 23:59:59',
      message: dailyOffDutyMessage,
    },
  ],
};

const configProd = {
  // customer message api服务
  CUSTOMER_MESSAGE_API_URL: 'https://gate.97kid.com/',
  CUSTOMER_MESSAGE_API_KEY: 'C33D20F60EA44AE2820D38BF16E44F7E',

  // s401 api key
  API_KEY: 'SEVMTE9jdXNUb21lcldPUktQUkVFRUZJTkU=',
  // 用户信息相关
  ADMIN_GET_ME_URL: 'https://gate.97kid.com/a/admins/me',
  TEACHER_GET_ME_URL: 'https://gate.97kid.com/t/teachers/me',
  // Mongodb
  MONGO: 'mongodb://192.168.10.85:27018,192.168.10.86:27018,192.168.10.87:27018/jiuqu_new_customer',
  MONGO_CONFIG: {
    useMongoClient: true,
  },

  // 又拍云文件上传相关
  UPLOAD_PATH: '/tmp/',
  UPYUN_API: 'v0.api.upyun.com',
  UPYUN_BUCKET: 'jiuqu-customer',
  UPYUN_NAME: 'jqcustomer',
  UPYUN_PASSWORD: 'abcde12345',
  UPYUN_SECRET: 'Sa0+xeVQ7KGTSb2XGaCae/Ez/CQ=',
  UPYUN_BUCKET_URL: 'http://jiuqu-customer.b0.upaiyun.com',

  // redis 相关
  REDIS_CONFIG: {
    port: 6379,
    host: 'r-bp11cabaf53a7434.redis.rds.aliyuncs.com',
    password: 'Jiuqu123',
    db: 0,
    max: 100,
    min: 1,
    timeout: 30000,
    log: false,
    dropBufferSupport: true,
  },
};

const configDev = {
  // customer message api服务
  CUSTOMER_MESSAGE_API_URL: 'http://localhost:8000/',
  CUSTOMER_MESSAGE_API_KEY: 'C33D20F60EA44AE2820D38BF16E44F7E',

  // s401 api key
  API_KEY: 'SEVMTE9jdXNUb21lcldPUktQUkVFRUZJTkU=',

  // customer running host
  ADMIN_GET_ME_URL: 'https://gate.97kid.com/a/admins/me',
  TEACHER_GET_ME_URL: 'https://gate.97kid.com/t/teachers/me',

  // Mongodb
  MONGO: 'mongodb://192.168.10.10/jiuqu_customer_test',
  MONGO_CONFIG: {
    useMongoClient: true,
  },

  // 又拍云文件上传相关
  UPLOAD_PATH: '~/gitlab/jiuqu-customer/backend/uploads/',
  UPYUN_API: 'v0.api.upyun.com',
  UPYUN_BUCKET: 'jiuqu-customer',
  UPYUN_NAME: 'jqcustomer',
  UPYUN_PASSWORD: 'abcde12345',
  UPYUN_SECRET: 'Sa0+xeVQ7KGTSb2XGaCae/Ez/CQ=',
  UPYUN_BUCKET_URL: 'http://jiuqu-customer.b0.upaiyun.com',

  // redis 相关
  REDIS_CONFIG: {
    port: 6379,
    host: '192.168.10.10',
    db: 2,
    max: 100,
    min: 1,
    timeout: 30000,
    log: false,
    dropBufferSupport: true,
    showFriendlyErrorStack: true,
  },
};

const config = env !== 'production' ? configDev : configProd;
export default assign(defaultConf, config);
